package com.xywy.tangandroid.sync;

import java.util.List;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.util.Log;

import com.xywy.tangandroid.bean.BloodData;
import com.xywy.tangandroid.greendao.BloodDataDao;
import com.xywy.tangandroid.greendao.BloodDataDao.Properties;

import de.greenrobot.dao.query.QueryBuilder;

/**
 * 同步当前的血糖数据
 */
public class SyncBloodData implements ISyncBleDevice {

	private Context mContext;
	private BloodDataDao bloodDataDao;
	private SharedPreferences sp;
	private Editor editor;
	private String userid = "";

	public SyncBloodData(Context context, BloodDataDao bloodDataDao) {
		this.mContext = context;
		this.bloodDataDao = bloodDataDao;
		sp = mContext.getSharedPreferences("config", Context.MODE_PRIVATE);
		editor = sp.edit();
		userid = sp.getString("userid", "");
	}

	@Override
	public List<?> getUnuploadData() {
		long lastSaveTime = sp.getLong("last_test_time_blood_presure", 1000); // 最后的上传时间
		QueryBuilder<BloodData> qb = bloodDataDao.queryBuilder();
		qb.orderAsc(Properties.Recordtime).where(Properties.Recordtime.gt(lastSaveTime));
		return qb.list();
	}

	@Override
	public void syncDataFormServer(List<?> datas) {

	}

	@Override
	public void uploadDataInRAM(List<?> datas) {

	}

}
